<?php
// +----------------------------------------------------------------------
// | 火凤凰CMS内容管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2018 http://cxbs.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 赵志广 <amdin@cxbs.net>
// +----------------------------------------------------------------------
namespace app\api\controller;

use app\common\controller\Apibase;
use app\common\model\UserAddress as cxModel;
use think\Loader;

class UserAddress extends Apibase {

    public function add(){
        $res['code'] = '0';
        $data = input('post.');
        $data = datatrim($data);
        $validate = Loader::validate('UserAddress');
        if(!$validate->scene('add')->check($data)){
            $res['msg'] = $validate->getError();
        }
        $cxmodel = new cxModel();
        $res['msg'] = '处理失败！';
        $data['addres'] = implode(',',$data['addres']);
        if(empty($data['id'])){
            if($cxmodel->allowField(true)->isUpdate(false)->save($data)){
                $res['code'] = '1';
                $res['msg'] = '添加成功！';
            }
        }else{
            if($cxmodel->allowField(true)->isUpdate(true)->save($data,['id'=>$data['id']])){
                $res['code'] = '1';
                $res['msg'] = '修改成功！';
            }
        }
        return json($res);
    }


}
